package com.ch.ms.service;

import com.ch.ms.data.domain.ChmsServer;

import java.util.Objects;

public interface ChmsServerCacheService extends MapleCacheService<String, ChmsServer> {


    public static final String CACHE_KEY_PREFIX = "maple:servers";

    @Override
    default String getKey(Object... args) {
        if (args[0] instanceof ChmsServer) {
            ChmsServer chmsServer = (ChmsServer) args[0];

            if (Objects.nonNull(chmsServer.getType())) {

                switch (chmsServer.getType()) {

                    case WORLD:
                        return String.format("%s:worlds", CACHE_KEY_PREFIX);

                    case LOGIN:
                        return String.format("%s:logins", CACHE_KEY_PREFIX);

                    case CHANNEL:
                        return String.format("%s:channels", CACHE_KEY_PREFIX);
                }
            }

        }

        return null;
    }
}
